Skip to content

Non uniform for everything! #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Firestar99
Copy link
Member

@Firestar99 Firestar99 commented Dec 11, 2024

Adds the NonUniform declaration to pretty much everything I could think of, even if it's not required. I don't think this will have a huge performance impact, as Nvidia and Intel don't seem to care about this flag, their accesses are always non-uniform, and Amd's driver is really good at figuring out whether something is uniform / scalar across the workgroup / subgroup or not.

To have NonUniform declared everywhere, you just need to enable it's associated capability: SpirvBuilder::capability(Capability::ShaderNonUniform)

closes #120

@LegNeato
Copy link
Collaborator

LegNeato commented May 21, 2025

I wonder if we should land this behind an off-by-default flag? Or maybe that is more trouble than it is worth.

@Firestar99
Copy link
Member Author

I'm shocked I haven't thought of this earlier... then I wouldn't have to keep updating this PR constantly

@Firestar99
Copy link
Member Author

Firestar99 commented Jun 2, 2025

@LegNeato Buffers are easy, but for images, we can't just cfg within an asm!:

asm! {
    // error[E0658]: attributes on expressions are experimental
    // error: removing an expression is not supported in this position
    #[cfg(feature = "non-uniform")]
    "OpDecorate %image NonUniform"
    ...
}

We can't put it in a separate asm! either as we need to decorate the access instruction and all it's parameters (as a precaution). The correct way would be to cfg the entire asm! and duplicate all the image access asm!, about 200 loc.

Would you mind if I just add a linking stage instead to remove all OpDecoration if the target feature ShaderNonUniform is not present? (cc @eddyb)

@LegNeato
Copy link
Collaborator

LegNeato commented Jun 7, 2025

I'm personally fine with either a linking stage or copying 200 lines (or a macro so no need to copy?)

@Firestar99
Copy link
Member Author

I've taken the linking stage filter route and added the NonUniform decoration it everywhere, hopefully didn't miss anything. Tested it on my project too.

I've added some tests in branch byte_adressable_buffer_from_runtime_array, which work on spv1.3 but fail on vulkan1.2. That behavior doesn't change on master, so unrelated to this PR. Weirdly enough, that's exactly how I'm using them in my project, yet it compiles with vulkan1.2 just fine.

@Firestar99 Firestar99 marked this pull request as ready for review June 7, 2025 16:05
@Firestar99 Firestar99 requested a review from schell as a code owner June 7, 2025 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Migrated] NonUniform decoration support
2 participants